<template>
  <view class="message">
    <view class="message-title"> {{ info.title || "" }} </view>
    <view class="message-time"> {{ formatTime(info.createtime) }} </view>
    <view class="message-content"> {{ info.body || "" }} </view>
  </view>
</template>
<script>
export default {
  data() {
    return {
      info_id: "", // 消息ID
      info: {
        title: "", // 标题
        body: "", // 内容
        createtime: "", // 消息时间
      },
    };
  },
  onLoad(e) {
    this.info_id = e.id;
    this.getInfo();
  },
  methods: {
    // 获取消息详情
    getInfo() {
      this.$https.get("/notice/detail", { id: this.info_id }).then((res) => {
        this.info = res.data;
      });
    },
    // 格式化日期
    formatTime(time) {
      if (!time) return "";
      let date = new Date(time * 1000);
      let y = date.getFullYear();
      let m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      let h = date.getHours();
      h = h < 10 ? "0" + h : h;
      let i = date.getMinutes();
      i = i < 10 ? "0" + i : i;
      let s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      return y + "-" + m + "-" + d + " " + h + ":" + i + ":" + s;
    },
  },
};
</script>
<style lang="scss" scoped>
.message {
  background-color: #ffffff;
  min-height: calc(100vh - 40rpx);
  padding: 20rpx 32rpx;
  &-title {
    color: #333;
    padding: 10rpx 0;
    font-size: 28rpx;
  }
  &-time {
    text-align: right;
    font-size: 26rpx;
    color: #999;
    margin-bottom: 10rpx;
  }
  &-content {
    color: #666;
    font-size: 26rpx;
    letter-spacing: 2rpx;
  }
}
</style>
